﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Songhay.Tests.Extensions
{
    using Songhay.Extensions;

    /// <summary>
    /// Tests for <see cref="StringExtensions"/>
    /// </summary>
    [TestClass]
    public class StringExtensionsTest
    {
        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext { get; set; }

        [TestMethod]
        public void ShouldGetSubstringInContext()
        {
            var input = "Lorem ipsum dolor";
            var searchText = "ipsum";
            var contextLength = 10;
            var actual = input.ToSubstringInContext(searchText, contextLength);

            Assert.IsTrue(actual.Contains(searchText), "The expected search text is not here.");
            Assert.IsTrue(actual.Length >= contextLength, "The expected text length is not here.");

            contextLength = 5;
            actual = input.ToSubstringInContext(searchText, contextLength);

            Assert.IsTrue(actual.Contains(searchText), "The expected search text is not here.");
            Assert.IsTrue(actual.Length == contextLength, "The expected text length is not here.");
        }
    }
}
